const gulp = require('gulp');
const fs = require('fs-extra');
const Reporter = require('lighthouse/lighthouse-core/report/report-generator');
const run = require("./tools/lighthouse-tool").run

gulp.task('Page Performance Test on mBlock Web', async function(){
    let timestamp = Date.now();
    let spent = [];
    for(let i=0; i<5; i++){
        spent.push(await run(timestamp, i));
    }
    let template = await fs.readFileSync('./summary/template/template.html', 'utf-8');
    let summary = Reporter.replaceStrings(template, [{
            search:"%%TIME_SPENT%%",
            replacement:JSON.stringify(spent)
        },
        {
            search:"%%TIMESTAMP%%",
            replacement:timestamp
        }
    ]);
    write(`./summary/report/summary@${timestamp}.html`, summary)
});

gulp.task('default', ['Page Performance Test on mBlock Web'])

